package com.cus.shd.sharingjdbc.controller;


import com.cus.shd.sharingjdbc.model.RecordOrderLog;
import com.cus.shd.sharingjdbc.service.RecordOrderLogService;
import com.cus.shd.sharingjdbc.switchDataSource.RecordOrderLogShardingBizService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author lcc
 * @since 2021-10-30
 */
@RestController
@RequestMapping("/recordOrderLog")
public class RecordOrderLogController {

    @Autowired
    private RecordOrderLogService recordOrderLogService;

    @Autowired
    private RecordOrderLogShardingBizService recordOrderLogShardingBizService;

    /**
     * 新增数据
     *
     * @return 单条数据
     */
    @GetMapping("/inertOrderLog")
    public ResponseEntity<Integer> inertOrderLog() {
        return ResponseEntity.ok(this.recordOrderLogService.insert());
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryByOrderDeliveryId/{id}")
    public ResponseEntity<RecordOrderLog> queryByOrderDeliveryId(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.recordOrderLogService.queryByOrderDeliveryId(id));
    }

    /**
     * 创建表（企业实战使用定时任务进行创建，不建议使用此方式）
     *
     */
    @GetMapping("/creatTable/{tableName}")
    public ResponseEntity<Integer> creatTable(@PathVariable("tableName") String tableName) {
        return ResponseEntity.ok(this.recordOrderLogService.createTable(tableName));
    }

    /**
     *
     *
     */
    @GetMapping("/test")
    public ResponseEntity<Integer> test() {
        return ResponseEntity.ok(this.recordOrderLogService.test());
    }


    /**
     *
     *
     */
    @GetMapping("/queryByShardingOrderDeliveryId/{id}")
    public ResponseEntity<RecordOrderLog> queryByShardingOrderDeliveryId(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.recordOrderLogShardingBizService.queryByShardingOrderDeliveryId(id));
    }


}
